package com.andy.android.usbmanager.log;

import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.andy.android.usbmanager.BuildConfig;

import java.util.ArrayList;
import java.util.List;

public class LogCall {

    private static final List<LogCallback> callbacks = new ArrayList<>();
    private static final Handler mainHandler = new Handler(Looper.getMainLooper());

    public static void registerCallback(LogCallback callback) {
        if (!callbacks.contains(callback)) callbacks.add(callback);
    }

    public static void unregisterCallback(LogCallback callback) {
        callbacks.remove(callback);
    }


    public static void d(String content) {
        if (BuildConfig.DEBUG) {
            mainHandler.post(new Runnable() {
                @Override
                public void run() {
                    Log.d("LOG", content);
                    for (LogCallback callback : callbacks) {
                        callback.onLog(content);
                    }
                }
            });
        }
    }
}
